﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using IronPython.Compiler;
using Microsoft.Scripting;
using System.Collections;
using JEPy;


namespace jepy_text1
{
    public class Ctest:ICtest
    {
        Hashtable tb;
        public int abc
        {
            get;set;
        }
        public Ctest()
        {
            abc = 10;
            tb=new Hashtable();
            tb.Add("aa",1);
            tb.Add("bb",2);
        }
        public void doMe()
        {
            Console.WriteLine(abc.ToString()+"ff");
        }
        public object this[string name]
        {
            get
            {
                return (int)(tb[name])+3;
            }
            set
            {
                tb[name] = value;
            }
        }
    }
    public interface ICtest
    {
        int abc
        {
            get;
            set;
        }


         void doMe();
    }

    class Program
    {
        static void Main(string[] args)
        {
            ScriptEngine PyEng = Python.CreateEngine();
            ScriptScope PySc =PyEng.CreateScope();

            //int a = 100;
            //PySc.SetVariable("a", 1.5);
            //PySc.SetVariable("b", 15);
            //Hashtable codeTable = new Hashtable();
            //ScriptSource code = PyEng.CreateScriptSourceFromFile("G:\\project\\epics\\epics_c#_pro\\In_progress\\example\\JtextEpics\\JEPlugIn\\PythonPlugIn\\test\\Jtext_ioc_jePyTest\\JePy\\run.py", Encoding.ASCII, SourceCodeKind.Statements);
            //codeTable.Add("code", code);
            //((ScriptSource)(codeTable["code"])).Execute(PySc);
            //code.Execute(PySc);
            //Console.WriteLine((PySc.GetVariable("b")).ToString());
             
            Ctest cc = new Ctest();
            PySc.SetVariable("cc", cc);
            PyEng.Execute("print cc[\"aa\"]", PySc);

            //PythonExe myPy = new PythonExe();
            //myPy.IniPyExe();
            //myPy.SetVarible("a", 15.5);
            //myPy.SetVarible("b", 10);
            
            //myPy.SetVarible("cc", cc);
            //myPy.addCodeFromFile("G:\\project\\epics\\epics_c#_pro\\In_progress\\example\\JtextEpics\\JEPlugIn\\PythonPlugIn\\test\\Jtext_ioc_jePyTest\\JePy\\run.py", "code");
            //myPy.ExcFromFile("G:\\project\\epics\\epics_c#_pro\\In_progress\\example\\JtextEpics\\JEPlugIn\\PythonPlugIn\\test\\Jtext_ioc_jePyTest\\JePy\\run.py");
            //myPy.ExeCode("code");
            
            //Console.WriteLine((myPy.GetVarible("b")).ToString());
            //PySc.SetVariable("abc", 15);
            //PyEng.Execute("abc+=15", PySc);
            //Console.WriteLine((PySc.GetVariable("abc")).ToString());
            //Console.ReadKey();
            //PyEng.Execute("abc+=15", PySc);
            //PyEng.Execute("abc+=15", PySc);
            //PySc.SetVariable("a", a);
            //PyEng.Execute("a+=15", PySc);
            //Console.WriteLine((PySc.GetVariable("a")).ToString());
            //Console.WriteLine(a.ToString());
            //var cc1 = new Ctest();
            //ICtest cc = cc1;
            //PySc.SetVariable("cc", cc);
            //PyEng.Execute("cc.abc+=10", PySc);
            //var code = PyEng.CreateScriptSourceFromString("cc.abc+=10", SourceCodeKind.Statements);
            ////code.Execute(PySc);
            //PyEng.Execute("cc.doMe()", PySc);
            //Console.WriteLine(((PySc.GetVariable("cc")).abc).ToString());
            //Console.WriteLine(cc.abc.ToString());
            Console.ReadKey();
            
        }
    }


}
